﻿using UnityEngine;
using UnityEngine.AI;

public class RandomWalker : MonoBehaviour
{
    NavMeshAgent agent;
    [SerializeField]
    private float duration = 8f;
    public float rad = 15f;
    void Start() => agent = GetComponent<NavMeshAgent>();

    void Update()
    {
        if (agent.pathPending || agent.remainingDistance > 0.1f) return;

        var pos = Random.insideUnitCircle * rad;

        var a_pos = agent.transform.position;

        var des = new Vector3(pos.x, a_pos.y, pos.y);

        agent.SetDestination(des);

        Debug.Log($"{nameof(RandomWalker)}: {des } - {agent.destination}");

        //Debug.DrawLine(a_pos, agent.destination, Color.red, duration);
        Debug.DrawRay(a_pos, agent.destination-a_pos, Color.red, duration);
    }

    private void OnGUI()
    {
        GUILayout.Label("这是一个测试");
        if (GUILayout.Button("点我"))
        {
            Debug.Log($"{nameof(RandomWalker)}: 点我....");
        }
    }

}
